//
//  WDProductBottomView.m
//  Zhihuijinfu
//
//  Created by 王笛 on 2016/12/9.
//  Copyright © 2016年 王笛. All rights reserved.
//

#import "WDProductBottomView.h"

@interface WDProductBottomView ()
/** 收藏按钮 */
@property (nonatomic, weak) UIButton *collectBtn;
@end

@implementation WDProductBottomView

+ (instancetype)productBottomView
{
    return [[self alloc] init];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        //收藏
        UIButton *collectBtn = [self creatBtnWithTitle:@"收藏" bgColor:ColorForRGB(0xf1a636) action:@selector(clickCollectBtn:)];
        
        [collectBtn setTitle:@"取消收藏" forState:UIControlStateSelected];
        
        self.collectBtn = collectBtn;
        
        [collectBtn makeConstraints:^(MASConstraintMaker *make) {
            make.left.bottom.equalTo(0);
            make.height.equalTo(48);
            make.width.equalTo(WDScale(100));
        }];
        
        //申请贷款
        UIButton *applyLoanBtn = [self creatBtnWithTitle:@"申请贷款" bgColor:WDNavSeleColor action:@selector(clickApplyBtn:)];
        
        [applyLoanBtn makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(collectBtn.right);
            make.height.equalTo(collectBtn.height);
            make.bottom.right.equalTo(0);
        }];
        
    }
    return self;
}

#pragma mark - 按钮点击
//收藏
- (void)clickCollectBtn:(UIButton *)sender
{
    [_delegate productBottomViewCollectWithButton:sender];
    
//    if (sender.isSelected) {
//        sender.backgroundColor = ColorForRGB(0xc7c7c7);
//    } else {
//        sender.backgroundColor = ColorForRGB(0xf1a636);
//    }
    
}

//申请贷款
- (void)clickApplyBtn:(UIButton *)sender
{
    [_delegate productBottomViewApplyLoanWithButton:sender];
}

#pragma mark - 创建控件
/** 创建按钮 */
- (UIButton *)creatBtnWithTitle:(NSString *)title bgColor:(UIColor *)bgColor action:(SEL)action
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [btn setTitle:title forState:UIControlStateNormal];
    
    btn.backgroundColor = bgColor;
    
    btn.titleLabel.font = [UIFont systemFontOfSize:16];
    
    btn.titleLabel.textColor = ColorForRGB(0xffffff);
    
    [btn addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:btn];
    
    return btn;
}

- (void)setCollect:(BOOL)collect
{
    _collect = collect;
    
    if (collect) {
        self.collectBtn.selected = YES;
        self.collectBtn.backgroundColor = ColorForRGB(0xc7c7c7);
    } else {
        self.collectBtn.selected = NO;
        self.collectBtn.backgroundColor = ColorForRGB(0xf1a636);
    }
}

@end
